<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<base href="<%=basePath%>" />
<title>Index</title>

<jsp:include page="../header.jsp"></jsp:include>

<script type="text/javascript">
	$(function() {
		$("#addTask").click(function() {
			showTaskPanel();
		});

        $('.selectpicker').selectpicker();
	});

	function showTaskPanel(id, name, admin, type) {
		$("#taskPanel [name='task.id']").val(id);
		$("#taskPanel [name='task.name']").val(name);
		$("#taskPanel [name='task.admin']").val(admin);
        $("#taskPanel [name='task.type']").selectpicker('val', type);
        $("#taskPanel").modal();
	}
</script>
</head>
<body>
	<jsp:include page="../top.jsp"></jsp:include>

	<div class="container theme-showcase" role="main">

		<div class="alert alert-success">
			<h2>任务列表</h2>
		</div>
		<div class="well">
			<div>
				<a class="btn btn-success" id="addTask">添加任务</a>
			</div>
		</div>

		<div id="taskList">
			<table class="table table-hover">
				<tr>
					<th>名称</th>
					<th>cron</th>
					<th>状态</th>
					<th>操作</th>
				</tr>
				<s:iterator value="taskList" var="d">
					<tr>
						<td><s:property value="#d.name" /></td>
						<td><s:property value="#d.cronExpression" /></td>
						<td><s:property value="#d.taskStatus.getStr()" /></td>
						<td>
							<div class="btn-group" role="group">
								<button type="button" class="btn btn-primary dropdown-toggle"
									data-toggle="dropdown" aria-haspopup="true"
									aria-expanded="false">
									操作 <span class="caret"></span>
								</button>
								<ul class="dropdown-menu">
									<li><a href="javascript:void(0);"
										onclick="showTaskPanel('<s:property value="#d.id"/>','<s:property value="#d.name"/>','<s:property value="#d.admin"/>','<s:property value="#d.type.toString()"/>');">修改</a></li>
									<li role="separator" class="divider"></li>
									<li><a
										href="task/deleteTask?task.id=<s:property value='#d.id'/>" onclick="return confirm('确认删除吗？');">删除</a></li>
								</ul>
							</div>
						</td>
					</tr>
				</s:iterator>
			</table>
		</div>
		<div class="modal fade" id="taskPanel" tabindex="-1" role="dialog"
			aria-labelledby="myModalLabel" aria-hidden="true">
			<form action="task/saveTask" method="post">
				<input type="hidden" name="task.id" />
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal"
								aria-label="Close">
								<span aria-hidden="true">&times;</span>
							</button>
							<h4 class="modal-title">任务信息</h4>
						</div>
						<div class="modal-body">
							<h4>
								<ul class="list-group">
									<li class="list-group-item"><label> 名称 </label> <input
										type="text" class="form-control" name="task.name"
										placeholder="名称" /></li>
									<li class="list-group-item"><label> 描述 </label> <input
											type="text" class="form-control" name="task.description"
											placeholder="描述" /></li>
									<li class="list-group-item"><label> 机器人 </label><br/>
										<select class="selectpicker" multiple="multiple" name="chatBotIdList" data-live-search="true">
											<s:iterator value="chatBotList" var="cb">
												<option value="<s:property value='#cb.id'/>"><s:property value="#cb.name"/></option>
											</s:iterator>
										</select>
									</li>
									<li class="list-group-item"><label> 状态 </label><br/>
										<select class="selectpicker" name="task.taskStatus" data-live-search="true">
											<option value="ENABLE" selected="selected">启用</option>
											<option value="DISABLE">禁用</option>
										</select>
									</li>
									<li class="list-group-item"><label> cron表达式 </label> <input
										type="text" class="form-control" name="task.cronExpression"
										placeholder="cron表达式" /></li>
									<li class="list-group-item"><label> 消息内容 </label> <input
											type="text" class="form-control" name="textMessage.text"
											placeholder="消息内容" /></li>
								</ul>
							</h4>
						</div>
						<div class="modal-footer">
							<button type="submit" class="btn btn-success">保存</button>
							<button type="button" class="btn btn-default"
								data-dismiss="modal">取消</button>
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
	<jsp:include page="../footer.jsp"></jsp:include>
</body>
</html>
